package com.hspedu.web.exception;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class MyExceptionHandler {
    @ExceptionHandler({ArithmeticException.class,NullPointerException.class})
    public String localException(Exception e, HttpServletRequest request){
        System.out.println("Exception message="+e.getMessage());
        request.setAttribute("reason",e.getMessage());
        return "exception_mes";
    }

    @RequestMapping("/test01")
    public String test01(Integer num){
        Integer result=9/num;
        return "success";
    }

    @RequestMapping("/testglobal02")
    public String testglobal02(Integer num){
        int hello = Integer.parseInt("hello");

        return "success";
    }
}
